<template>
	<app-page>
		<wd-config-provider :theme="theme">
			<view class="container">
				<view class="form">
					<wd-form ref="formRef" :model="formData" :rules="formRules">
						<wd-picker clearable prop="type" :columns="caseTypeList" v-model="formData.type"
							custom-class="wd-picker-custom-class-fd-col square bg-transparent" label="选择案件类型：" />
						<wd-picker clearable prop="involve" :columns="amountInvolved" v-model="formData.involve"
							custom-class="wd-picker-custom-class-fd-col square bg-transparent" label="是否涉及财产：" />
						<view class="form-item" v-if="formData.involve === '是'">
							<wd-cell required title="涉及资产（元）" vertical>
								<wd-input v-model="formData.money" prop="money" placeholder="请输入涉及资产" />
							</wd-cell>
						</view>
					</wd-form>
				</view>
				<view class="result card">
					<wd-cell-group>
						<wd-cell title="受理费（元）" :value="calculateResult.accept" />
						<wd-cell title="执行费（元）" :value="calculateResult.execute" />
						<wd-cell title="保全费（元）" :value="calculateResult.preservation" />
					</wd-cell-group>
				</view>
				<view class="tips">本标准是按湖北省武汉市标准计算，其他地区可能存在部分差异</view>
				<view class="footer">
					<wd-button @click="calculate" type="success"
						custom-class="wd-button-custom-class-my-success square wd-button-custom-class-w100">
						计算
					</wd-button>
				</view>
			</view>
		</wd-config-provider>
	</app-page>
</template>

<script lang="ts">
	import { defineComponent, reactive, ref } from 'vue';

	import { onPageScroll, onLoad } from '@dcloudio/uni-app';
	import useRouter from '@/hooks/useRouter';



	export default defineComponent({
		name: '',
		components: {},
		setup(props, ctx) {
			// 日间light、夜间dark主题
			const theme = ref('light');
			const formRef = ref();
			const formData = reactive({
				type: "",
				involve: "否",
				money: "0", // 涉及资产金额，用于计算
			})
			const formRules = reactive({
				type: [
					{ required: true, message: '请选择案件类型', trigger: 'blur' }
				],
				involve: [
					{ required: true, message: '请选择是否涉及金额', trigger: 'blur' }
				],
				money: [
					{ required: true, message: '请输入涉及金额（元）', trigger: 'blur' }
				],
			})
			const caseTypeList = ref([
				{
					label: '婚姻案件'
				},
				{
					label: '侵害人身权案件'
				},
				{
					label: '其他非财产案件'
				},
				{
					label: '劳动争议案件'
				},
				{
					label: '知识产权纠纷案件'
				},
				{
					label: '破产案件'
				},
				{
					label: '商标、专利、海事行政案件'
				},
				{
					label: '其他行政案件'
				},
				{
					label: '管辖权异议'
				},
				{
					label: '财产案件'
				},
				{
					label: '申请支付令'
				},
				{
					label: '申请公示催告'
				},
				{
					label: '申请撤销仲裁裁决或者认定仲裁协议效力'
				}
			]) // 案件类型列表数据
			const amountInvolved = ref([
				{
					label: '是'
				},
				{
					label: '否'
				},
			])
			// 保全费
			const getPreservation = (money : any) => {
				// 低于1000 算30一件
				if (Number(money) <= 1000) {
					return 30;
					// 大于1000 小于10万 0.01% + 20元
				} else if (Number(money) > 1000 && Number(money) <= 100000) {
					return Number(money) * 0.01 + 20;
					// 小于等于10万部分 按照  0.01% + 20元  大于10万部分 0.005% 最高5000元
				} else if (Number(money) > 100000) {
					let temp = (Number(money) - 100000) * 0.005 + (100000 * 0.01 + 20);
					if (temp <= 5000) {
						return temp
					} else {
						return 5000
					}
				}
			}
			// 执行费
			const getExecute = (money : any) => {
				// 小于 1万 按照 50一件
				if (Number(money) <= 10000) {
					return 50;
				} else if (Number(money) > 10000 && Number(money) <= 500000) {
					// 大于1万 小于50万 1.5% - 100元
					return Number(money) * 0.015 - 100;
				} else if (Number(money) > 500000 && Number(money) <= 5000000) {
					// 大于50万 小于500万 1% + 2400元
					return Number(money) * 0.01 + 2400
				} else if (Number(money) > 5000000 && Number(money) <= 10000000) {
					// 大于500万 小于1000万 0.5% + 27400元
					return Number(money) * 0.01 + 27400
				} else if (Number(money) > 10000000) {
					// 大于1000万 0.1% + 67400元
					return Number(money) * 0.001 + 67400
				}
			}
			const getProperty = (money : any) => {
				// 小于 1万 按照 50一件
				if (Number(money) <= 10000) {
					return 50;
				} else if (Number(money) > 10000 && Number(money) <= 100000) {
					// 超过1万元至10万元：诉讼标的额×2.5%-200元
					return Number(money) * 0.025 - 200;
				} else if (Number(money) > 100000 && Number(money) <= 200000) {
					// 超过10万元至20万元：诉讼标的额×2%+300元
					return Number(money) * 0.02 + 300;
				} else if (Number(money) > 200000 && Number(money) <= 500000) {
					// 超过20万元至50万元：诉讼标的额×1.5%+1300元
					return Number(money) * 0.015 + 1300;
				} else if (Number(money) > 500000 && Number(money) <= 1000000) {
					// 超过50万元至100万元：诉讼标的额×1%+3800元
					return Number(money) * 0.01 + 3800;
				} else if (Number(money) > 1000000 && Number(money) <= 2000000) {
					// 超过100万元至200万元：诉讼标的额×0.9%+4800元
					return Number(money) * 0.009 + 4800;
				} else if (Number(money) > 2000000 && Number(money) <= 5000000) {
					// 超过200万元至500万元：诉讼标的额×0.8%+6800元
					return Number(money) * 0.008 + 6800;
				} else if (Number(money) > 5000000 && Number(money) <= 10000000) {
					// 超过500万元至1000万元：诉讼标的额×0.7%+11800元
					return Number(money) * 0.007 + 11800;
				} else if (Number(money) > 10000000 && Number(money) <= 20000000) {
					// 超过1000万元至2000万元：诉讼标的额×0.6%+21800元
					return Number(money) * 0.006 + 21800;
				} else if (Number(money) > 20000000) {
					// 超过2000万元：诉讼标的额×0.5%+41800元
					return Number(money) * 0.005 + 41800;
				}
			}
			const calculateResult = ref({
				accept: "0.00", // 受理费
				preservation: "0.00", // 保全费
				execute: "0.00", // 执行费
			}) // 计算结果数据
			const calculateList = {
				'婚姻案件': (involve : any, money : number) => {
					// 受理费
					let accept : any = "50.00-300.00";
					// 保全费
					let preservation : any = "30.00";
					// 执行费
					let execute : any = "50.00-500.00"
					if (involve === '是') {
						preservation = getPreservation(money)
						execute = getExecute(money)
						if (Number(money) > 200000) {
							let extra = Number(money) - 200000;
							accept = 300 + (extra * 0.005)
							accept = accept.toFixed(2)
						}
						preservation = preservation.toFixed(2)
						execute = execute.toFixed(2)
					}
					return {
						accept,
						preservation,
						execute,
					}
				},
				'侵害人身权案件': (involve : any, money : number) => {
					// 受理费
					let accept : any = "100.00-500.00";
					// 保全费
					let preservation : any = "30.00";
					// 执行费
					let execute : any = "50.00-500.00"
					if (involve === '是') {
						preservation = getPreservation(money)
						execute = getExecute(money)
						if (Number(money) == 50000) {
							accept = 500
						} else if (Number(money) > 50000 && Number(money) <= 100000) {
							let extra = Number(money) - 50000;
							accept = 500 + (extra * 0.01)
						} else if (Number(money) > 100000) {
							let temp = 100000 * 0.01;
							let extra = Number(money) - 100000;
							accept = temp + (extra * 0.005)
						}
						accept = accept.toFixed(2)
						preservation = preservation.toFixed(2)
						execute = execute.toFixed(2)
					}
					return {
						accept,
						preservation,
						execute,
					}
				},
				'其他非财产案件': (involve : any, money : number) => {
					// 受理费
					let accept : any = "50.00-100.00";
					// 保全费
					let preservation : any = "30.00";
					// 执行费
					let execute : any = "50.00-500.00"
					if (involve === '是') {
						preservation = getPreservation(money)
						execute = getExecute(money)
						preservation = preservation.toFixed(2)
						execute = execute.toFixed(2)
					}
					return {
						accept,
						preservation,
						execute,
					}
				},
				'劳动争议案件': (involve : any, money : number) => {
					// 受理费
					let accept : any = "10.00";
					// 保全费
					let preservation : any = "30.00";
					// 执行费
					let execute : any = "50.00-500.00"
					if (involve === '是') {
						preservation = getPreservation(money)
						execute = getExecute(money)
						preservation = preservation.toFixed(2)
						execute = execute.toFixed(2)
					}
					return {
						accept,
						preservation,
						execute,
					}
				},
				'知识产权纠纷案件': (involve : any, money : number) => {
					// 受理费
					let accept : any = "500.00-1000.00";
					// 保全费
					let preservation : any = "30.00";
					// 执行费
					let execute : any = "50.00-500.00"
					if (involve === '是') {
						accept = getProperty(money)
						preservation = getPreservation(money)
						execute = getExecute(money)
						accept = accept.toFixed(2);
						preservation = preservation.toFixed(2)
						execute = execute.toFixed(2)
					}
					return {
						accept,
						preservation,
						execute,
					}
				},
				'破产案件': (involve : any, money : number) => {
					// 受理费
					let accept : any = "50.00";
					// 保全费
					let preservation : any = "30.00";
					// 执行费
					let execute : any = "50.00-500.00"
					if (involve === '是') {
						accept = getProperty(money)
						accept = accept / 2
						if (accept > 300000) {
							accept = 300000
						}
						preservation = getPreservation(money)
						execute = getExecute(money)
						accept = accept.toFixed(2);
						preservation = preservation.toFixed(2)
						execute = execute.toFixed(2)
					}
					return {
						accept,
						preservation,
						execute,
					}
				},
				'商标、专利、海事行政案件': (involve : any, money : number) => {
					// 受理费
					let accept : any = "100.00";
					// 保全费
					let preservation : any = "30.00";
					// 执行费
					let execute : any = "50.00-500.00"
					if (involve === '是') {
						preservation = getPreservation(money)
						execute = getExecute(money)
						preservation = preservation.toFixed(2)
						execute = execute.toFixed(2)
					}
					return {
						accept,
						preservation,
						execute,
					}
				},
				'其他行政案件': (involve : any, money : number) => {
					// 受理费
					let accept : any = "50.00";
					// 保全费
					let preservation : any = "30.00";
					// 执行费
					let execute : any = "50.00-500.00"
					if (involve === '是') {
						preservation = getPreservation(money)
						execute = getExecute(money)
						preservation = preservation.toFixed(2)
						execute = execute.toFixed(2)
					}
					return {
						accept,
						preservation,
						execute,
					}
				},
				'管辖权异议': (involve : any, money : number) => {
					// 受理费
					let accept : any = "50.00-100.00";
					// 保全费
					let preservation : any = "30.00";
					// 执行费
					let execute : any = "50.00-500.00"
					if (involve === '是') {
						preservation = getPreservation(money)
						execute = getExecute(money)
						preservation = preservation.toFixed(2)
						execute = execute.toFixed(2)
					}
					return {
						accept,
						preservation,
						execute,
					}
				},
				'财产案件': (involve : any, money : number) => {
					// 受理费
					let accept : any = "50.00";
					// 保全费
					let preservation : any = "30.00";
					// 执行费
					let execute : any = "50.00-500.00"
					if (involve === '是') {
						accept = getProperty(money)
						accept = accept.toFixed(2);
						preservation = getPreservation(money)
						execute = getExecute(money)
						preservation = preservation.toFixed(2)
						execute = execute.toFixed(2)
					}
					return {
						accept,
						preservation,
						execute,
					}
				},
				'申请支付令': (involve : any, money : number) => {
					// 受理费
					let accept : any = "50.00";
					// 保全费
					let preservation : any = "30.00";
					// 执行费
					let execute : any = "50.00-500.00"
					if (involve === '是') {
						accept = getProperty(money)
						accept = accept / 3;
						accept = accept.toFixed(2);
						preservation = getPreservation(money)
						execute = getExecute(money)
						preservation = preservation.toFixed(2)
						execute = execute.toFixed(2)
					}
					return {
						accept,
						preservation,
						execute,
					}
				},
				"申请公示催告": (involve : any, money : number) => {
					// 受理费
					let accept : any = "100.00";
					// 保全费
					let preservation : any = "30.00";
					// 执行费
					let execute : any = "50.00-500.00"
					if (involve === '是') {

						preservation = getPreservation(money)
						execute = getExecute(money)
						preservation = preservation.toFixed(2)
						execute = execute.toFixed(2)
					}
					return {
						accept,
						preservation,
						execute,
					}
				},
				"申请撤销仲裁裁决或者认定仲裁协议效力": (involve : any, money : number) => {
					// 受理费
					let accept : any = "400.00";
					// 保全费
					let preservation : any = "30.00";
					// 执行费
					let execute : any = "50.00-500.00"
					if (involve === '是') {
						preservation = getPreservation(money)
						execute = getExecute(money)
						preservation = preservation.toFixed(2)
						execute = execute.toFixed(2)
					}
					return {
						accept,
						preservation,
						execute,
					}
				},
			}
			const calculate = () => {
				formRef.value.validate().then(({ err, valid }) => {
					if (valid) {
						let { involve, money, type } = formData; // 获取涉及金额和是否涉及金额的值
						// 计算函数，根据案件类型和涉及金额计算费用，并返回结果。
						const temp = calculateList[formData.type](involve, money);
						calculateResult.value = temp;
					}
				})

			}
			return {
				theme,
				formData,
				formRules,
				caseTypeList,
				amountInvolved,
				calculateList,
				calculate,
				calculateResult,
				formRef,
			};
		}
	});
</script>
<!-- #ifdef MP-WEIXIN -->
<style lang="less">
	page {
		background-color: #f2f2f2;
	}
</style>
<!-- #endif -->
<style lang="less" scoped>
	.container {
		padding: 24rpx;
		background-color: #f2f2f2;

		.form {
			.checkbox {
				padding: 18rpx;
			}


			.form-item {
				padding: 18rpx !important;
				border-radius: 14rpx;
				overflow: hidden;

				:deep(.wd-textarea) {
					padding: 24rpx;
					border-radius: 14rpx;
				}

				:deep(.wd-input) {
					padding: 0 24rpx;
					border-radius: 14rpx;

					.wd-input__inner {
						height: 44px;
						line-height: 44px;
					}
				}

				:deep(.wd-cell) {
					background-color: transparent;
					padding-left: 0;

					.wd-cell__wrapper {
						padding-right: 0;
						padding: 0;
					}

					.wd-cell__right {
						margin-top: 20rpx;
					}

					.wd-cell__wrapper.is-vertical .wd-cell__value {
						max-width: 100%;
					}

					.wd-cell__body {
						// background-color: #FFF;
						border-radius: 14rpx;
					}
				}

			}
		}

		.result {
			margin: 18rpx;
			width: calc(100% - 18rpx - 18rpx);
			overflow: hidden;
		}

		.tips {
			margin: 18rpx;
			color: #c91c1f;
			font-size: 22rpx;
		}

		.footer {
			margin-top: 24rpx;
			padding: 18rpx;
		}
	}
</style>